﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QD.Data.Json
{
    public delegate String JsonSerializeHandle(object @object);

    public class JsonHelper
    {
        static IDictionary<String, JsonSerializeHandle> repository = null;
        public static String Serialize(Type type, object @object, StringBuilder sb = null)
        {
            if (sb == null) sb = new StringBuilder();
            sb.Append(repository[type.FullName](@object));
            return sb.ToString();
        }
        static object lobject = new object();
        public static void AddSerializeType(Type type, JsonSerializeHandle handle)
        {
            lock (lobject)
            {
                if (repository == null) repository = new Dictionary<String, JsonSerializeHandle>();
                repository.Add(type.FullName, handle);
            }
        }

    }
}
